package gui;

import javax.swing.JFrame;
import javax.swing.JPanel;

import client.ChatClient;
import clientPackage.ClientConsole;

import common.ChatIF;
import javax.swing.JButton;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;

public class AcademicFrame extends JFrame implements ChatIF{
	private LoginPanel _login;
//	ChatClient client;
	public static ClientConsole myclient;
	public static String userID=null;
	private String myHost;
	private int port;
	public boolean allow=true;
	public ArrayList<Object> answer;

	public AcademicFrame(String host, int port)
	{
		super();
		

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	//	this.client = myclient;
		this.myHost = host;
		this.port = port;
		_login=new LoginPanel(this);
		initialize();
	}
	private void initialize() {
		this.setSize(300, 300);
		this.setContentPane(_login);
		this.setTitle("Academic Managment Tool");
		myclient = new ClientConsole (myHost,port,this);
		
	}
	@Override
	public void display(Object message) { // Server calls sendToClient which calls this function
		// TODO Auto-generated method stub
		 ChatIF currentPanel = (ChatIF) this.getContentPane(); // Refers to the active JPanel which implements ChatIF
		 currentPanel.display(message); // call the referer JPanel's display method
		 answer = (ArrayList<Object>) message; // save answer for refference
	}
	
	
	public String getHost()
	{
		return this.myHost;
	}

	public void setClient(ChatClient myclient)
	{
		//this.client = myclient;
	}
	
	public static void logOff()
	{
		ArrayList<Object> logOff = new ArrayList<Object>();
		logOff.add("logOff");
		logOff.add(userID);
		AcademicFrame.myclient.sendMessageToServer(logOff);
	}
	

}
